package com.info.zhiduoduo.repository.mapper.order;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.info.zhiduoduo.repository.dto.OrderBriefDto;
import com.info.zhiduoduo.repository.entity.order.Order;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author bob
 * @since 2018-12-27
 */
public interface OrderMapper extends BaseMapper<Order> {

	@Select("select o.orderid,o.orderno,o.payno,o.price,o.refundamount,o.state,o.createtime,o.userid," +
			"o.projectid,cp.projectname,cp.compid,cp.reject_reason,cp.arbitrate_remark,us.username,u.phone " +
			"from zdd_order o " +
			"join zdd_company_project cp on cp.projectid = o.projectid " +
			"and if(#{compid}=0, 1=1, cp.compid=#{compid}) " +
			"and cp.projectname like '%${projectname}%' " +
			"join zdd_maker u on u.userid = o.userid " +
			"join zdd_maker_studio us on us.userid = o.userid " +
			"and us.username like '%${username}%' " +
			"where if(#{state}='', 1=1, o.state in(${state})) " +
			"and (orderno like '%${orderno}%' or payno like '%${payno}%') " +
			"and o.createtime BETWEEN #{startDate} AND #{endDate}")
	List<OrderBriefDto> getOrderList(@Param("compid") int compid, @Param("projectname") String projectname, @Param("username") String username, @Param("orderno") String orderno,
	                                 @Param("payno") String payno, @Param("startDate") Date startDate, @Param("endDate") Date endDate, @Param("state") String state);
}
